/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */

package org.jaxson.struts.charts;


import java.io.Serializable;

import org.jaxson.struts.BaseAction;
import org.jaxson.struts.encoder.ResponseContentType;

/**
 * Struts action which returns the image map for a given chart.
 * The image map can be added to the dom dynamically.  It's recommended
 * to invoke this action from the "onload" of an chart <code>img</code> tag.
 * 
 * @author Joe Maisel
 */
public class ImageMapAction extends BaseAction
{
	private String imageId;

	/**
	 * @see org.jaxson.struts.BaseAction#handle()
	 */
	@Override
	public String handle()
	{
		enableResponseType( ResponseContentType.json );
		setResponseContentType( ResponseContentType.json );

		if( imageId != null )
		{
			setModel( (Serializable) session.getAttribute( sessionKey( imageId ) ) );
		}

		return null;
	}

	/**
	 * The images html "id" attribute.
	 * 
	 * @return the imageId
	 */
	public String getImageId()
	{
		return imageId;
	}

	/**
	 * The images html "id" attribute.
	 * 
	 * @param imageId
	 *            the imageId to set
	 */
	public void setImageId( String imageId )
	{
		this.imageId = imageId;
	}

	/**
	 * Returns the HttpSession key for a given image id.
	 * 
	 * @param imageId
	 * @return
	 */
	public static String sessionKey( String imageId )
	{
		return "image-map-" + imageId;
	}

	private static final long serialVersionUID = -7498253541136659362L;
}
